<template>
  <div>
    <el-descriptions v-loading="formLoading" :column="1" border label-width="230">
      <el-descriptions-item :label="t('studentPatent.fields.studentCode')">
        {{ processVo.studentCode }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.studentName')">
        {{ processVo.studentName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.mentorName')">
        {{ processVo.mentorName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.patentName')">
        {{ processVo.patentName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.attachment')">
        <IMRUpload
          v-model="processVo.attachment"
          :file-type="['pdf']"
          :file-size="20"
          :limit="1"
          disabled
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.patentType')">
        <dict-tag
          v-if="processVo.patentType"
          :type="DICT_TYPE.RESEARCH_PATENT_TYPE"
          :value="processVo.patentType"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.patentStatus')">
        <dict-tag
          v-if="processVo.patentStatus"
          :type="DICT_TYPE.RESEARCH_PATENT_STATUS"
          :value="processVo.patentStatus"
        />
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.patentStatus === '已公开'"
        :label="t('studentPatent.fields.publishNumber')"
      >
        {{ processVo.publishNumber }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.patentStatus === '已公开'"
        :label="t('studentPatent.fields.publishTime')"
      >
        {{ processVo.publishTime ? formatDate(processVo.publishTime, 'YYYY-MM-DD') : '' }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.patentStatus === '已授权'"
        :label="t('studentPatent.fields.patentNumber')"
      >
        {{ processVo.patentNumber }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.patentStatus === '已授权'"
        :label="t('studentPatent.fields.patentTime')"
      >
        {{ processVo.patentTime ? formatDate(processVo.patentTime, 'YYYY-MM-DD') : '' }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.personalRanking')">
        <dict-tag
          v-if="processVo.personalRanking"
          :type="DICT_TYPE.RESEARCH_PATENT_PERSONAL_RANK"
          :value="processVo.personalRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.casRanking')">
        <dict-tag
          v-if="processVo.casRanking"
          :type="DICT_TYPE.RESEARCH_PATENT_USTC_RANK"
          :value="processVo.casRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.imrRanking')">
        <dict-tag
          v-if="processVo.imrRanking"
          :type="DICT_TYPE.RESEARCH_PATENT_IMR_RANK"
          :value="processVo.imrRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPatent.fields.remark')">
        {{ processVo.remark }}
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script setup lang="ts">
import { ProcessVoApi } from '@/api/bpm/processvo'
import { DICT_TYPE } from '@/utils/dict'
import IMRUpload from '@/components/IMRUpload/index.vue'
import { formatDate } from '@/utils/formatTime'
import { StudentPatentVO } from '@/api/core/studentpatent'
import { propTypes } from '@/utils/propTypes'

defineOptions({ name: 'BpmPatentDetail' })

const props = defineProps({
  id: propTypes.string.def(undefined)
})

const { query } = useRoute() // 查询参数
const { t } = useI18n() // 国际化

const queryId = query.id as unknown as string // 从 URL 传递过来的 流程实例ID

const processVo = ref<StudentPatentVO>({} as StudentPatentVO)

const formLoading = ref(false)

onMounted(async () => {
  formLoading.value = true
  const response = await ProcessVoApi.getProcessVoByProcessInstanceId(props.id || queryId)
  formLoading.value = false
  processVo.value = JSON.parse(response.vo)
})
</script>
